<!DOCTYPE html>
<html class="x-admin-sm">

<head>
  {include file="public/head"}
</head>

<body>
  <div class="x-body">
    <form class="layui-form">
      <input type="hidden" name="id" value="{$data.item.id}">
      <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: #FF5722;">*</span>课程</label>
        <div class="layui-input-inline">
          <select name="c_id">
            <option value="0"></option>
            {volist name="data.course" id="vo"}
            <option value="{$vo.id}" <?php if($data['item']['c_id']==$vo['id']){echo 'selected';}?>>{$vo.title}</option>
            {/volist}
          </select>
        </div>
        <label class="layui-form-label"><span style="color: #FF5722;">*</span>图片地址</label>
        <div class="layui-input-inline">
          <input type="text" class="layui-input" name="img" value="{$data.item.img}">
        </div>
        <label class="layui-form-label"><span style="color: #FF5722;">*</span>跳转链接</label>
        <div class="layui-input-inline">
          <input type="text" class="layui-input" name="url" value="{$data.item.url}">
        </div>
      </div>

      <div class="layui-form-item">
        <label class="layui-form-label">课程简介</label>
        <div class="layui-input-block" style="width: 810px;">
          <textarea id="desc" style="width: 798px;height: 250px;padding: 5px;">{$data.item.desc}</textarea>
        </div>
      </div>
    </form>
    <hr />
    <div class="layui-form-item">
      <div class="layui-input-block">
        <button class="layui-btn" onclick="save()">保存</button>
      </div>
    </div>
  </div>
  <script>
    layui.use(['element', 'form', 'upload'], function () {
      layer = layui.layer;
      var element = layui.element;
      var form = layui.form;
      var upload = layui.upload;
    })
    // 保存管理员
    function save() {
      var params = {
        id: parseInt($('input[name="id"]').val()),
        c_id: $('select[name="c_id"]').val(),
        desc: $.trim($('#desc').val()),
        img: $.trim($('input[name="img"]').val()),
        url: $.trim($('input[name="url"]').val())
      }

      if (params.c_id == 0) {
        layer.alert('请选择课程', { icon: 2 });
        return;
      }
      if (params.desc == 0) {
        layer.alert('请输入课程简介', { icon: 2 });
        return;
      }
      if (params.img == '') {
        layer.alert('请输入图片地址', { icon: 2 });
        return;
      }
      if (params.url == '') {
        layer.alert('请输入跳转地址', { icon: 2 });
        return;
      }

      $.post('/admin.php/desc/save', params, function (res) {
        if (res.code > 0) {
          layer.alert(res.msg, { icon: 2 });
        } else {
          layer.msg(res.msg);
          setTimeout(function () { parent.window.location.reload(); }, 1000);
        }
      }, 'json');
    }
  </script>
</body>

</html>